package JavaSe;

import java.io.ObjectInputStream;
import java.util.HashSet;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}10:44
 */
public class Name {
    private String first;
    private String last;

    public Name(String first, String last) {
        this.first = first;
        this.last = last;
    }

    public boolean equals(Object obj){
        if (this == obj){
            return true;
        }
        if (obj.getClass() == Name.class){
            Name n = (Name) obj;
            return n.first.equals(first);
        }
        return false;
    }

    public int hashCode(){
        return first.hashCode();
    }

    @Override
    public String toString() {
        return "Name{" +
                "first='" + first + '\'' +
                ", last='" + last + '\'' +
                '}';
    }

    static class Test{
        public static void main(String[] args) {
            HashSet<Name> set = new HashSet<>();
            set.add(new Name("abc","132"));
            set.add(new Name("abc","132"));
            System.out.println(set);
        }
    }
}
